﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Htx.Fur.Core.Extensions
{
    public static class PropertyExtensions
    {
        /// <summary>
        /// 给对象复制
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj">需要复制的对象</param>
        /// <param name="propertyName">属性名称</param>
        /// <param name="value">所赋的值</param>
        public static void SetPropertyValue<T>(this T obj, string propertyName, object value)where T: class, new()
        {
            var type = typeof(T);
            var property = type.GetProperty(propertyName);
            if (property == null)
            {
                throw new ArgumentException($"对象不存在属性 [{propertyName}]。");
            }
            property.SetValue(obj, value);
        }
    }
}
